package com.minelx.statementsplus.common;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Splitter {
	public <E> List<List<E>> split(List<E> elements, int count) {
		List<List<E>> result = Stream.generate(LinkedList<E>::new)
				.limit(count)
				.collect(Collectors.toList());
		for (int at = 0; at < elements.size(); at++) {
			E element = elements.get(at);
			int partitionIndex = at % count;
			result.get(partitionIndex).add(element);
		}
		return result;
	}

	public static <E> List<List<E>> splitting(List<E> elements, int count) {
		return new Splitter().split(elements, count);
	}
}
